/*******************************************************************/
/* @ All Rights Reserved Copyright (C) 2014 broada,Co.,Ltd.        */
/*                                                                 */
/*  NAME      = test_cics.c                                        */
/*  NOTE      =                                                    */
/*  DATE      = 2016/02/19 by songbb                               */
/*******************************************************************/

#include <stdio.h>
#include <CUnit/Basic.h>

#include "apmtest_cunit.h"
#include "frcomm.h"
#include "frmem.h"
#include "frservice_mng.h"

#include "../../src/module/cics/config.h"
#include "t_cics_comm/t_cics_comm.h"
#include "t_cics_core/t_cics_core.h"
#include "t_cics_packet/t_cics_packet.h"
#include "t_cics_header/t_cics_header.h"
#include "t_cics_gateway/t_cics_gateway.h"
#include "t_cics_eci/t_cics_eci.h"
#include "t_cics_mar/t_cics_mar.h"

static Frmemstat_mng g_st_memstat_mng = {0, FR_MEMSTAT_COUNT_MAX};
static pthread_rwlock_t g_memstat_rwlock = PTHREAD_RWLOCK_INITIALIZER;
static Frmem_env g_st_mem_env = {&g_st_memstat_mng, &g_memstat_rwlock};

int main(int argc, char **argv)
{
    if (fr_slab_init(&g_st_mem_env, MODULE_NAME) == NULL)
        return FR_FAIL;

    apmtest_cunit_registry();

    FunType fun_suites[1024];
    memset(fun_suites, 0x00, sizeof(fun_suites));
    int i_suites_len = sizeof(fun_suites) / sizeof(FunType);
    int i_loop = 0;

    // 加载各个测试组件
    // t_cics_comm
    apmtest_cunit_add_suites(fun_suites, i_suites_len, add_suite_cics_free);
    apmtest_cunit_add_suites(fun_suites, i_suites_len, add_suite__cics_frtime2datetimestr);
    apmtest_cunit_add_suites(fun_suites, i_suites_len, add_suite_cics_bin_to_hex_string);
    apmtest_cunit_add_suites(fun_suites, i_suites_len, add_suite_cics_packet_is_in_fragment);
    apmtest_cunit_add_suites(fun_suites, i_suites_len, add_suite_cics_report_msg_data_req);
    apmtest_cunit_add_suites(fun_suites, i_suites_len, add_suite_cics_report_msg_data_resp);

    // t_cics_header
    apmtest_cunit_add_suites(fun_suites, i_suites_len, add_suite_cics_header_detect);
    apmtest_cunit_add_suites(fun_suites, i_suites_len, add_suite_cics_header_unpack);

    // t_cics_packet
    apmtest_cunit_add_suites(fun_suites, i_suites_len, add_suite_cics_init_packet);
    apmtest_cunit_add_suites(fun_suites, i_suites_len, add_suite__cics_pkt_is_fragmented);
    apmtest_cunit_add_suites(fun_suites, i_suites_len, add_suite__cics_packet_check_fragment);
    apmtest_cunit_add_suites(fun_suites, i_suites_len, add_suite_cics_packet_unfragment);

    // t_cics_gateway
    apmtest_cunit_add_suites(fun_suites, i_suites_len, add_suite_cics_gateway);

    // t_cics_mar
    apmtest_cunit_add_suites(fun_suites, i_suites_len, add_suite_cics_mar_get_boolean);
    apmtest_cunit_add_suites(fun_suites, i_suites_len, add_suite_cics_mar_get_string);
    apmtest_cunit_add_suites(fun_suites, i_suites_len, add_suite_cics_mar_get_utf);

    // t_cics_eci
    apmtest_cunit_add_suites(fun_suites, i_suites_len, add_suite_cics_eci_req);
    apmtest_cunit_add_suites(fun_suites, i_suites_len, add_suite_cics_eci_resp);

    // t_cics_core
    apmtest_cunit_add_suites(fun_suites, i_suites_len, add_suite__cics_private_session_init);
    apmtest_cunit_add_suites(fun_suites, i_suites_len, add_suite__cics_analyze_direct);
    apmtest_cunit_add_suites(fun_suites, i_suites_len, add_suite_cics_detect);
    apmtest_cunit_add_suites(fun_suites, i_suites_len, add_suite__cics_destroy_session);
    apmtest_cunit_add_suites(fun_suites, i_suites_len, add_suite__cics_destroy_packet);
    apmtest_cunit_add_suites(fun_suites, i_suites_len, add_suite__cics_destroy_stmt);
    apmtest_cunit_add_suites(fun_suites, i_suites_len, add_suite_cics_session_destroy);
    apmtest_cunit_add_suites(fun_suites, i_suites_len, add_suite_cics_analyze);

    for (; i_loop < i_suites_len; i_loop++)
    {
        if (fun_suites[i_loop] != NULL && fun_suites[i_loop]() != 0)
        {
            CU_cleanup_registry();
            return CU_get_error();
        }
    }

    apmtest_cunit_unregistry();

    fr_slab_destroy();

    return 0;
}
